/*
* @Author: Flora
* @Date:   2019-01-16 09:03:12
* @Last Modified by:   Flora
* @Last Modified time: 2019-01-22 08:58:21
*/
'use strict';
require('./index.css');
require('page/common/nav/index.js');
require('page/common/footer/index.css');
var _account = require('service/account-service.js');
var templateIndex = require('./index.string');
var _mm = require('util/mm.js');


var account={
	// 账务列表
	accountList : [],
	init : function(){
		var _this = this;
		_this.getAccountList();
	},
	// 获取列表
	getAccountList : function(){
		var _this = this;
		_account.getAccountList(function(resData){
			// 获取成功
			// console.log('获取成功');
			_this.accountList = resData;//账目列表
			_this.render();
			_this.getSum();
		}, function(){
			alert('获取失败，请重试');
		});
	},
	// 获得总价
	getSum : function(){
		var _this = this;
		var sum = 0 ;
		for(var i=0 ; i < _this.accountList.length ; i++){
			sum = sum + _this.accountList[i].totalPrice;
		}
		$('#ip-sm').text(sum);
		// console.log(sum);
	},
	// 渲染
	render : function(){
		var _this = this;
		var accountTable = _mm.renderHtml(templateIndex,{
			accountList : _this.accountList
		});
		$('.tb-account').html(accountTable);
	}
};
$(function(){
	account.init();
});
